package com.sky.mapper;

import com.sky.dto.GoodsSalesDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface ReportMapper {

    @Select("select sum(amount) from orders where checkout_time >= #{begin} and checkout_time <= #{end} and status = 5")
    Integer sumTurnover(LocalDateTime begin, LocalDateTime end);

    @Select("select count(*) from user where create_time <= #{endTime} and create_time >= #{beginTime}")
    Integer countUser(LocalDateTime beginTime, LocalDateTime endTime);

    Integer countOrder(LocalDateTime beginTime, LocalDateTime endTime, Integer status);

    @Select("select name, sum(od.number) as number from orders o left join order_detail od\n" +
            "on o.id = od.order_id where checkout_time >= #{begin} and checkout_time <= #{end} and status = 5\n" +
            "group by name\n" +
            "order by number desc limit 0,10")
    List<GoodsSalesDTO> getSalesTop10(LocalDateTime begin, LocalDateTime end);
}
